Skip to content

[3.13] gh-142560: prevent use-after-free in search-like methods by exporting buffer in bytearray (GH-142938)#142986

Merged
serhiy-storchaka merged 3 commits into
python:3.13from
cmaloney:backport-220f0b1-3.13
Dec 24, 2025
Merged

[3.13] gh-142560: prevent use-after-free in search-like methods by exporting buffer in bytearray (GH-142938)#142986
serhiy-storchaka merged 3 commits into
python:3.13from
cmaloney:backport-220f0b1-3.13

Conversation

@cmaloney

@cmaloney cmaloney commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

This backport is more intricate as free threading / locking / critical sections was only added to bytearray in 3.14. This drops all critical section pieces (thread-safety for bytearray was added in 3.14)

this makes bytearray safer in 3.13 (The methods that use _bytearray_with_buffer should now be thread safe as it does the critical section), but I did not make all the methods thread safe that are thread safe in 3.14 (Without the clinic annotation doing so well is a lot more difficult)

(cherry picked from commit 220f0b1)

… by exporting buffer in bytearray (pythonGH-142938)

(cherry picked from commit 220f0b1)

Co-authored-by: wangxiaolei <fatelei@gmail.com>
@vstinner

Copy link
Copy Markdown
Member

Sadly, the build fails :-(

@cmaloney

cmaloney commented Dec 19, 2025

Copy link
Copy Markdown
Contributor Author

Will work on resolving in a bit; free threaded build worked for me... i need to improve my local tools for doing multiple builds

@cmaloney

Copy link
Copy Markdown
Contributor Author

Updated to drop the critical sections / locking

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

But the NEWS entry should be in the Core and Builtins section.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We don't support Free Threading in Python 3.13.

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) December 24, 2025 19:01
@serhiy-storchaka serhiy-storchaka merged commit a9e068f into python:3.13 Dec 24, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants